#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    FILE *fp = NULL;
    char rd_buf[100] = {0};
    char wr_buf[] = "https://blog.csdn.net/Romeo_tune";
    int ret;

    if(NULL == (fp = fopen(argv[1], "w+"))){
        perror("fopen error");
        exit(-1);
    }

    printf("open file \"%s\" success!\n", argv[1]);

    if(sizeof(wr_buf) > fwrite(wr_buf, 1, sizeof(wr_buf), fp)){
        printf("fwrite error!\n");
        fclose(fp);
        exit(-1);
    }

    printf("write file \"%s\" success!\nsize: %ld, buffer: %s\n", argv[1],sizeof(wr_buf),wr_buf);


    if(0 > fseek(fp, 0, SEEK_SET)){
        perror("fseek error");
        fclose(fp);
        exit(-1);
    }

    if(sizeof(wr_buf) > (ret = fread(wr_buf, 1, sizeof(wr_buf), fp))){
        if(ferror(fp)){
            printf("fread error!\n");
            fclose(fp);
            exit(-1);
        }
    }

    printf("read file \"%s\" success!\nsize: %d, buffer: %s\n", argv[1],ret,wr_buf);
    
    fclose(fp);
    exit(0);
}

